package flc.ast.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.databinding.DialogAddFolderBinding;
import stark.common.basic.base.BaseSmartDialog;

public class AddFolderDialog extends BaseSmartDialog<DialogAddFolderBinding> implements View.OnClickListener {

    public AddFolderDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_add_folder;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivDialogAddFolderClear.setOnClickListener(this);
        mDataBinding.tvDialogAddFolderCancel.setOnClickListener(this);
        mDataBinding.tvDialogAddFolderConfirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvDialogAddFolderCancel:
                dismiss();
                break;
            case R.id.tvDialogAddFolderConfirm:
                dismiss();
                if (!TextUtils.isEmpty(mDataBinding.etDialogAddFolderText.getText().toString().trim())) {
                    if (listener != null) {
                        listener.clickAddFolder(mDataBinding.etDialogAddFolderText.getText().toString());
                    }
                } else {
                    ToastUtils.showShort(R.string.please_input_folder_name);
                }
                break;
            case R.id.ivDialogAddFolderClear:
                mDataBinding.etDialogAddFolderText.setText("");
                break;
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickAddFolder(String name);
    }
}
